<template name="firm_delete">
  <view class="container">

    <!-- 删除功能列表 -->
    <view class="delete-list">
      <view 
        v-for="(item, index) in deleteOptions" 
        :key="index"
        class="delete-item"
        :class="{ disabled: item.disabled }"
      >
        <view class="delete-info">
          <text class="delete-title">{{ item.name }}</text>
          <text class="delete-desc">{{ item.description }}</text>
        </view>
        <button 
          class="delete-btn"
          :class="{ 'btn-disabled': item.disabled }"
          :disabled="item.disabled || !firm_id"
          @click="handleDelete(item)"
        >
          {{ item.disabled ? '已删除' : '删除' }}
        </button>
      </view>
    </view>


  </view>
</template>

<script>
export default {
  data() {
    return {
      deleteOptions: [
        {
          name: '删除仓库的全部订单',
          type: 'daleteFirmAllOrder',
          description: '清除该仓库所有订单记录',
          disabled: false
        },
        {
          name: '删除仓库的全部用户',
          type: 'daleteFirmAllUser',
          description: '清除该仓库所有用户数据',
          disabled: false
        },
        {
          name: '删除仓库的全部分类以及目录',
          type: 'daleteFirmAllHeader',
          description: '清除商品分类和目录结构',
          disabled: false
        },
        {
          name: '删除仓库的用户分组',
          type: 'daleteFirmAllGroup',
          description: '清除用户分组设置',
          disabled: false
        },
        {
          name: '删除仓库的商品',
          type: 'daleteFirmAllGoods',
          description: '清除所有商品信息',
          disabled: false
        },
        {
          name: '删除仓库的商品品牌',
          type: 'daleteFirmAllGoodsBrand',
          description: '清除商品品牌数据',
          disabled: false
        },
        {
          name: '删除仓库的商品规格',
          type: 'daleteFirmAllGoodsType',
          description: '清除商品规格属性',
          disabled: false
        },
        {
          name: '删除仓库的用户价格分组',
          type: 'daleteFirmAllUserLevel',
          description: '清除价格分组设置',
          disabled: false
        },
        {
          name: '删除仓库的用户价格分组卡密',
          type: 'daleteFirmAllUserLevelCard',
          description: '清除价格分组卡密数据',
          disabled: false
        },
        {
          name: '删除仓库的第三方推荐小程序',
          type: 'daleteFirmAllMPApplet',
          description: '清除第三方小程序配置',
          disabled: false
        },
        {
          name: '删除仓库的活动',
          type: 'daleteFirmAllplan',
          description: '清除所有营销活动',
          disabled: false
        },
        {
          name: '删除仓库的打印记录',
          type: 'daleteFirmAllPrintOrderType',
          description: '清除打印历史记录',
          disabled: false
        },
        {
          name: '删除仓库的打印配置',
          type: 'daleteFirmAllPrintSetting',
          description: '清除打印设置配置',
          disabled: false
        },
        {
          name: '删除仓库的线路',
          type: 'daleteFirmAllRoute',
          description: '清除配送线路设置',
          disabled: false
        },
        {
          name: '删除仓库',
          type: 'daleteFirmAllFirm',
          description: '清除仓库的设置',
          disabled: false
        }
      ]
    }
  },
  // 此处定义传入的数据
  props: { 
  	firm_id:{
  		type: String,
  		default: ''
  	},
  	firm_name:{
  		type: String,
  		default: ''
  	},
  },
  methods: {
    // 处理删除操作
    handleDelete(item) {
      if (!this.firm_id) {
        uni.showToast({
          title: '请输入仓库ID',
          icon: 'none'
        })
        return
      }

      if (item.disabled) {
        return
      }

	 var that = this
      // 二次确认
      uni.showModal({
        title: '危险操作',
        content: `确定要${item.name}吗？此操作不可逆！`,
        confirmColor: '#ff4757',
        confirmText: '确认删除',
        success: (res) => {
          if (res.confirm) {
            that.executeDelete(item)
          }
        }
      })
    },

    // 执行删除操作
    executeDelete(item) {
		var that = this

		that.$common.get_request(
			{
				type: item.type,
				id:this.firm_id,
			},
			(res)=>{
				that.$common.showModal('提示',res.msg)
				
				item.disabled = true
				
			}
		);
	  
    },

  }
}
</script>

<style>
.container {
  padding: 30rpx;
  background-color: #f5f6f7;
  min-height: 100vh;
}

/* 删除列表 */
.delete-list {
  height: calc(100vh - 300rpx);
  display: grid;
  grid-template-columns: 3fr;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.delete-item {
  background: #fff;
  padding: 30rpx;
  border-radius: 16rpx;
  margin-bottom: 20rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
  margin: 20px;
  
}

.delete-item.disabled {
  background: #f8f9fa;
  opacity: 0.6;
}

.delete-info {
  flex: 1;
  margin-right: 20rpx;
}

.delete-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #333;
  display: block;
  margin-bottom: 8rpx;
}

.delete-desc {
  font-size: 24rpx;
  color: #666;
  display: block;
}

/* 删除按钮 */
.delete-btn {
  background: #ff4757;
  color: #fff;
  border: none;
  border-radius: 12rpx;
  padding: 16rpx 32rpx;
  font-size: 26rpx;
  font-weight: 500;
  min-width: 120rpx;
  transition: all 0.3s ease;
}

.delete-btn:active {
  background: #ff3742;
  transform: scale(0.95);
}

.delete-btn[disabled] {
  background: #ddd !important;
  color: #999 !important;
  transform: none !important;
}

.btn-disabled {
  background: #ddd;
  color: #999;
}



</style>